#include "order_widget_logic.h"

OrderWidgetLogic::OrderWidgetLogic(OrderWidgetUI *ui, QObject *parent)
    : QObject(parent), ui(ui)
{
    ui->getLabel12()->setText(QString::number(calculateTotalAmount(), 'f', 2));
}

void OrderWidgetLogic::addProduct(double price, int quantity)
{
    products.append({price, quantity});
    double totalAmount = calculateTotalAmount();
    ui->getLabel12()->setText(QString::number(totalAmount, 'f', 2));
}

double OrderWidgetLogic::calculateTotalAmount()
{
    double totalAmount = 0.0;
    for (const auto &product : products)
    {
        totalAmount += product.first * product.second;
    }
    return totalAmount;
}

OrderWidgetLogic::~OrderWidgetLogic() {}
